package cn.bigcontainer.alt.sys.util;

import java.util.Map;

import cn.bigcontainer.alt.common.util.WoKit;
import cn.bigcontainer.alt.sys.dto.UserDto;
import cn.bigcontainer.alt.sys.exception.SysException;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class SysUtil {

	/**
	 * 从session中获取当前用户数据，获取不到不抛出异常，返回null
	 * @param map
	 * @return
	 */
	public static UserDto getCurrentUser (Map<String, Object>map) {
		if (map.get(SysConstant.SESSION_USER) == null) {
			return null;
		}
		return (UserDto)map.get(SysConstant.SESSION_USER);
	}
	
	/**
	 * 从session中获取当前用户数据，获取不到要抛异常
	 * @param map
	 * @return
	 */
	public static UserDto getCurrentUserWithException (Map<String, Object>map) {
		UserDto currentUser = getCurrentUser (map);
		if (currentUser == null) {
			throw new SysException(SysException.ERR_LOGIN_NOT);
		}
		return currentUser;
	}
	
	public static void main(String[] args) {
		log.info(WoKit.getMD5("3", "cailei"));
	}

}
